package srx.open.com.activity;

import android.os.Bundle;

import cn.bmob.v3.listener.BmobUpdateListener;
import cn.bmob.v3.update.BmobUpdateAgent;
import cn.bmob.v3.update.UpdateResponse;
import cn.bmob.v3.update.UpdateStatus;
import srx.open.com.R;
import srx.open.com.utils.Log;
import srx.open.com.utils.OpenToast;

/**
 * 主页面.
 *
 * @author hailongqiu 356752238@qq.com
 */
public class HomeActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initAllDatas();
        initAllWidgets();
        checkAppUpload();
    }

    /**
     * 检验APP是否需要更新.
     */
    public void checkAppUpload() {
//        BmobUpdateAgent.initAppVersion(this);
        BmobUpdateAgent.setUpdateOnlyWifi(false);
        BmobUpdateAgent.setUpdateListener(new BmobUpdateListener() {
            @Override
            public void onUpdateReturned(int updateStatus, UpdateResponse updateInfo) {
                if (updateStatus == UpdateStatus.Yes) {//版本有更新
                    Log.d(TAG, "版本有更新");
                } else if (updateStatus == UpdateStatus.No) {
                    Log.d(TAG, "已经是最新版本");
                } else if (updateStatus == UpdateStatus.EmptyField) {//此提示只是提醒开发者关注那些必填项，测试成功后，无需对用户提示
                    OpenToast.showMsg("请检查你AppVersion表的必填项，1、target_size（文件大小）是否填写；2、path或者android_url两者必填其中一项。");
                } else if (updateStatus == UpdateStatus.IGNORED) {
                    Log.d(TAG, "该版本已被忽略更新");
                } else if (updateStatus == UpdateStatus.ErrorSizeFormat) {
                    OpenToast.showMsg("请检查target_size填写的格式，请使用file.length()方法获取apk大小。");
                } else if (updateStatus == UpdateStatus.TimeOut) {
                    OpenToast.showMsg("查询出错或查询超时");
                }
            }
        });
        BmobUpdateAgent.update(this);
    }

}
